package com.mall.controller;


import com.mall.pageResult.PageResult;
import com.mall.pojo.OmsOrderReturnReason;
import com.mall.service.OmsOrderReturnReasonService;
import com.mall.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/returnReason")
@Slf4j
public class OmsOrderReturnReasonController {

    @Autowired
    private OmsOrderReturnReasonService omsOrderReturnReasonService;
    /**
     * 添加退货原因
     *
     */
    @PostMapping("/create")
    public Result<Integer> createOrderReturnReason(@RequestBody OmsOrderReturnReason omsOrderReturnReason){
        log.info("用户添加数据:"+omsOrderReturnReason.toString());
        omsOrderReturnReason.setCreateTime(new Date());
        //调用omsOrderReturnReasonService方法进行添加
       Integer createNum =  omsOrderReturnReasonService.createOrderReturnReason(omsOrderReturnReason);
        //返回
        return Result.success(createNum,"操作成功");
    }

    /**
     * 删除退货原因
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public Result<Integer> deleteOrderReturnReason(@RequestParam("ids") List<Integer> ids){
        //调用方法进行删除
       Integer deleteNum =  omsOrderReturnReasonService.deleteOrderReturnReasonByIds(ids);
        return Result.success(deleteNum,"操作成功");

    }

    /**
     * 分页查询功能
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public Result<PageResult<OmsOrderReturnReason>> list(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                                         @RequestParam(value = "pageSize", required = false) Integer pageSize){
//调用service进行分页查询操作
       PageResult<OmsOrderReturnReason> pageRe = omsOrderReturnReasonService.findOrderReturnReasonList(pageNum,pageSize);
       return Result.success(pageRe,"操作成功");
    }

    /**
     * 修改退货原因数据回显
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<OmsOrderReturnReason> orderInfoReturn(@PathVariable Integer id){
        log.info("要回显得id:"+id);
        //调用方法进行回显
        OmsOrderReturnReason omR = omsOrderReturnReasonService.findOrderInfoById(id);
        //返回数据
        return Result.success(omR,"操作成功");
    }

    /**
     * 修改用户退货原因
     * @param omsOrderReturnReason
     * @return
     */
    @PostMapping("/update/{id}")
    public Result<Integer> updateOrderInfoReturn(@RequestBody OmsOrderReturnReason omsOrderReturnReason){
            //调用service中的方法,返回受影响行数
      Integer updateNum = omsOrderReturnReasonService.updateOrderInfoReturn(omsOrderReturnReason);
      //返回结果
        return Result.success(updateNum,"操作成功");
    }

    /**
     * 修改退货状态
     * @param ids
     * @param status
     * @return
     */
    @PostMapping("/update/status")
    public Result<Integer> updateOrderInfoReturnStatus(@RequestParam(value = "ids") List<Integer> ids,
                                                       @RequestParam(value = "status") Integer status){

        //调用方法进行修改状态
       Integer updateNum =  omsOrderReturnReasonService.updateOrderInfoReturnStatus(ids,status);

       return Result.success(updateNum,"操作成功");
    }


}
